/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.officialusr.controller
 * FILE    NAME: OfficialUsrDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.jodinfo.outmirror.entity.OfficialUsrEntity;
import com.jodinfo.outmirror.service.OfficialUsrBizService;
import com.jodinfo.outmirror.util.ResponseEntity;
import com.jodinfo.outmirror.util.SysConstant;



@Controller
@RequestMapping(value = "/OfficialUsrAdmin")
public class OfficialUsrController  {
	
@Resource(name="officialUsrBizService")
private OfficialUsrBizService officialUsrBizService;

@RequestMapping(value = "/login")
public @ResponseBody String login(OfficialUsrEntity officialUsrEntity,HttpServletRequest request) {
	ResponseEntity rs = null;
	rs =  officialUsrBizService.queryByEntity(officialUsrEntity);
	if (rs.getStatus().equals(SysConstant.SUCCESS)) {
		HttpSession session = request.getSession();
		session.setAttribute("user",officialUsrEntity);
	}
	return JSON.toJSONString(rs); 
}


@RequestMapping(value = "/logOut")
public ModelAndView logOut(OfficialUsrEntity officialUsrEntity,HttpServletRequest request,HttpServletResponse response) {
	 request.getSession().removeAttribute("user");
     return  new ModelAndView("redirect:/officialMain/login");
}

/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String OfficialUsrList(OfficialUsrEntity officialUsrEntity) {
	if(officialUsrEntity==null){
		officialUsrEntity = new OfficialUsrEntity();
		officialUsrEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		officialUsrEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	officialUsrEntity.setIsDel(SysConstant.IS_DEL_N);
	String str = officialUsrBizService.queryListForPageOfficialUsr(officialUsrEntity);
	return str;
}
/**
* OfficialUsrEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView officialUsrListPage(OfficialUsrEntity officialUsrEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("officialUsrList"));
}
/**
* OfficialUsrEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView officialUsrEditPage(OfficialUsrEntity officialUsrEntity) {
	
	return new ModelAndView(returnPath("officialUsrAdd"));
}
/**
 * 查询OfficialUsrEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findOfficialUsrData(HttpServletRequest request) {
	String id = request.getParameter("id");
	OfficialUsrEntity officialUsrEntity =  officialUsrBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(officialUsrEntity); 
}

/**
 * 保存或更新OfficialUsr 
 * 
 * */
@RequestMapping(value = "/saveOfficialUsr")
public @ResponseBody String saveOfficialUsrData(@RequestBody OfficialUsrEntity officialUsrEntity) {
	ResponseEntity rs = null;
	if(officialUsrEntity!=null){
		if(officialUsrEntity.getId()!=null){
			rs = officialUsrBizService.updateOfficialUsr(officialUsrEntity);
		}else{
			rs = officialUsrBizService.addOfficialUsr(officialUsrEntity);
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出OfficialUsrEntity
 * @author zhuxiaoliu
 * @date 2015-7-09  下午2:13:28
 * @return
 */
//@RequestMapping(value = "/exportOfficialUsrExcel")
//public void exportOfficialUsrExcel(OfficialUsrEntity officialUsrEntity,HttpServletResponse response) {
//	officialUsrEntity.setIsDel(SysConstant.IS_DEL_N);
//	officialUsrBizService.exportOfficialUsr(officialUsrEntity, response);
//}


 /**
 * 
 * 批量删除
 * @author zhuxiaoliu
 * @date 2017年3月13日 下午2:48:57
 * @param officialUsrEntity
 * @return
 */
@RequestMapping(value = "/batchDelOfficialUsr")
public @ResponseBody String batchDelOfficialUsr(OfficialUsrEntity officialUsrEntity) {
	ResponseEntity rs = null;
	//rs = officialUsrBizService.batchDelOfficialUsr(officialUsrEntity);
	return  JSON.toJSONString(rs);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/officialusr/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
